package com.example.compose.ui.camera

import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.unit.dp

@Composable
fun ClickEffect(enable:Boolean){

    val dps = animateDpAsState(targetValue = if (enable) 70.dp else 100.dp,
        animationSpec = tween(if (enable) 200 else 0,if (enable) 0 else 200, LinearEasing)
    )

    Canvas(modifier = Modifier
        .size(dps.value)
        .clip(RoundedCornerShape(1.dp))
    ){
        val canvasWidth = size.width  // 画布的宽
        val canvasHeight = size.height  // 画布的高
        val path = Path()

        path.moveTo(canvasWidth / 5, 0f)
        path.lineTo(0f, 0f)
        path.lineTo(0f, canvasHeight/5)

        path.moveTo(canvasWidth / 5 * 4, 0f)
        path.lineTo(canvasWidth, 0f)
        path.lineTo(canvasWidth, canvasHeight/5)

        path.moveTo(0f, canvasHeight / 5 * 4 )
        path.lineTo(0f, canvasHeight)
        path.lineTo(canvasWidth/5, canvasHeight)

        path.moveTo(canvasWidth / 5 * 4, canvasHeight)
        path.lineTo(canvasWidth, canvasHeight)
        path.lineTo(canvasWidth, canvasHeight/ 5 * 4)

        drawPath(
            path = path,
            color = if (enable) Color.White else Color.Transparent,
            style = Stroke(width = 10f)
        )

    }
}